package com.dtguai.app.util.redis;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author guoLiang
 * @date 2020年3月31日16:59:31
 */
@Component
@AllArgsConstructor
public class RedisUtil {

    private final StringRedisTemplate redisTemplate;

    public static final int TIME_OUT_DEF = 60 * 60 * 2;

    /**
     * hash get 系列
     */
    public Object getHash(String hashKey, String key) {
        return redisTemplate.opsForHash().get(hashKey, key);
    }

    /**
     * hash set 系列
     */
    public void setHash(String collectionKey, Object key, Object value) {
        redisTemplate.opsForHash().put(collectionKey, key.toString(), JSON.toJSONString(value));
        redisTemplate.expire(collectionKey, TIME_OUT_DEF, TimeUnit.SECONDS);
    }


}